#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
int main(int argc, char *argv[])
{

    printf("主进程ID: %d\n", getpid());

    int status;
    pid_t child_pid;

    child_pid = fork();

    if (child_pid == 0)
    {

        printf("子进程ID: %d\n", getpid());

        sleep(2);

        printf("子进程结束\n");

        exit(0);
    }
    else
    {

        printf("父进程ID: %d\n", getpid());

        waitpid(child_pid, &status, 0);

        printf("父进程结束\n");
    }

    return 0;
}